package com.gxgeek.service;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author gaoxing
 * @create 2018-06-08 下午3:24
 */
@Component
public class CacheService {

    private LoadingCache<String, Object> caches = CacheBuilder.newBuilder()
            .maximumSize(2000)
            .expireAfterWrite(10, TimeUnit.MINUTES)
            .build(new CacheLoader<String, Object>() {
                @Override
                public Object load(String key) throws Exception {
                    return null;
                }
            });


    public Object getValue(String cacheKey) {
        Object result = caches.getIfPresent(cacheKey);
        return result;

    }

    public void storeValue(String cacheKey, int expireTime, Object result) {
        caches.put(cacheKey, result);
    }
}
